package com.wujilee.payservice.service;


import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse;
import com.wechat.pay.java.service.retailstore.model.OrderInfo;
import com.wujilee.payservice.config.WeixinPayConfig;

import javax.annotation.Resource;


/**
 * @author liwuji
 * @date 2024/6/17
 * @desc
 **/
public class PayServiceImpl implements PayService{
    @Resource
    private NativePayService nativePayService;
    @Resource
    private WeixinPayConfig weixinPayConfig;
    @Override
    public String nativePayOrder(OrderInfo orderInfo) {
        // request.setXxx(val)设置所需参数，具体参数可见Request定义
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal( orderInfo.getTotalFee().intValue());
        request.setAmount(amount);
        request.setAppid(weixinPayConfig.getAppid());
        request.setMchid(weixinPayConfig.getMerchantId());
        request.setDescription("测试商品标题");
        request.setNotifyUrl(weixinPayConfig.getNotifyUrl());
        request.setOutTradeNo(orderInfo.getOutTradeNo());
        PrepayResponse response = nativePayService.prepay(request);
        return null;
    }
}
